<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
</head>

<body>
    <script src="https://cdn.bootcdn.net/ajax/libs/decimal.js/10.2.0/decimal.min.js">
    </script>
    <script>
        console.log('加法：');
        var a = 0.1;
        var b = 0.2;
        console.log(a + b);

        console.log(new Decimal(a).add(new Decimal(b)).toNumber());
        console.log('减法：');
        var a = 1.0;
        var b = 0.7;
        console.log(a - b);
        console.log(new Decimal(a).sub(new Decimal(b)).toNumber());
        console.log('乘法：');
        var a = 1.01;
        var b = 1.003;
        console.log(a * b);
        console.log(new Decimal(a).mul(new Decimal(b)).toNumber());
        console.log('除法：');
        var a = 0.029;
        var b = 10;
        console.log(a / b);
        console.log(new Decimal(a).div(new Decimal(b)).toNumber());
    </script>
</body>

</html>